package com.controller;

import com.domain.Order;
import com.domain.User;
import com.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.service.UserloginService;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.swing.*;
import java.io.IOException;
import java.util.List;


@Controller
@RequestMapping("/gst")
public class Usercontroller {


    @Autowired
    private UserloginService userservice;


    @Autowired
    private OrderService orderservice;



/*
    @RequestMapping("/findalluser")
    public ModelAndView findalluser(HttpServletRequest request,  ServletResponse response) throws IOException {
        ModelAndView modelAndView = new ModelAndView();
        String name=(String) request.getParameter("name");
        String pwd=(String) request.getParameter("pwd");
        User user =new User() ;
        user.setName(name);
        user.setPwd(pwd);
        List<User> search1=userservice.findalluser();
        List<Order> search2=orderservice.findallorder();
        response.setContentType("text/html;charset=utf-8");
        request.getSession().setAttribute("USER_SESSION","exist");

        try {
            if (name.equals("") || pwd.equals("")) {
                JOptionPane.showMessageDialog(null, "输入数值不能为空");
                modelAndView.setViewName("login");
                return modelAndView;
            }
            for (User one : search1) {
                if (name.equals(one.name) && pwd.equals(one.pwd)) {
                    JOptionPane.showMessageDialog(null, "登录成功");
                    modelAndView.addObject("userdata", search1);
                    modelAndView.addObject("orderdata", search2);
                    modelAndView.setViewName("admin/success");
                    return modelAndView;
                }
            }
            JOptionPane.showMessageDialog(null, "不存在该账号或密码");
            modelAndView.setViewName("login");
            return modelAndView;
        }catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "不可访问 没有登录");
            modelAndView.setViewName("login");
            return modelAndView;
        }

    }*/

}
